#!/bin/bash

install_python(){
    yum install openssl-devel -y
    #wget --no-check-certificate http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
    #tar xvf Python-2.7.3.tar.bz2 
    #cd Python-2.7.3
    wget http://mirrors.sohu.com/python/2.7.9/Python-2.7.9.tar.xz
    tar xvf Python-2.7.9.tar.xz
    cd Python-2.7.9
    ./configure 
    make &&  make install
    mv /usr/bin/python /usr/bin/python2.6.6
    ln -s /usr/local/bin/python2.7 /usr/bin/python
    sed -i 's/python/python2.6.6/g' /usr/bin/yum
}

install_setuptools(){
    wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-20.6.7.tar.gz#md5=45d6110f3ec14924e44c33411db64fe6
    tar xvf setuptools-20.6.7.tar.gz
    cd setuptools-20.6.7
    python setup.py install
    ln -s /usr/local/bin/easy_install /usr/bin/easy_install
}

install_pip(){
    wget --no-check-certificate https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
    tar xvf pip-9.0.1.tar.gz    
    cd pip-9.0.1
    python setup.py install
}

update_pip(){
    mkdir -p /root/.pip
cat > /root/.pip/pip.conf << EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
EOF
}

#下载安装Python2.7
install_python
#安装setuptools
install_setuptools
#安装pip
install_pip
#更新pip源
update_pip
